package person.bing.fbcloud.leetcode;

/**
 * @author: mengfanbing
 * @date: 2020/10/10 10:18
 */
public class Q24 {
    public static void main(String[] args) {

    }

    public static ListNode swapPairs(ListNode head) {
        util(new ListNode(),head);
        return head;
    }

    public static void util(ListNode previous,ListNode current) {
        if (current == null || current.next == null){
            return;
        }
        ListNode next = current.next;
        ListNode third = next.next;
        if (previous != null){
            previous.next = next;
        }
        next.next = current;
        current.next = third;
        util(current,third);
    }

}
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
